package com.pureut.storage.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.pureut.storage.domain.PickingRestDetail;
import com.pureut.storage.dto.PickingRestDto;
import com.pureut.storage.export.PickingRestExport;
import com.pureut.storage.service.PickingRestService;
import com.pureut.storage.util.ExcelUtil;
import com.pureut.storage.vo.PickingRestDbVo;
import com.pureut.storage.vo.PickingRestVo;
import com.pureut.storage.vo.UpdateDocVo;
import com.sale.common.core.domain.R;
import com.sale.common.core.web.controller.BaseController;
import com.sale.common.log.annotation.Log;
import com.sale.common.log.enums.BusinessType;
import com.sale.common.mybatis.core.page.PageQuery;
import com.sale.common.mybatis.core.page.TableDataInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 其他出库控制层
 * @author: CM
 * @date: 2022/12/28  17:38
 */
@RestController
@RequestMapping("/pickingRest")
public class PickingRestController extends BaseController {

    @Resource
    PickingRestService pickingRestService;

    /**
     * 新增其他出库
     */
    //@SaCheckPermission("warehouse:outbound:otherout:add")
    //@Log(title = "新增其他出库", businessType = BusinessType.INSERT)
    @PostMapping("/addRest")
    public R<Void> addRest(@RequestBody PickingRestVo pickingRestVo) throws Exception {
        return toAjax(pickingRestService.addRest(pickingRestVo));
    }

    /**
     * 修改其他出库
     */
    //@SaCheckPermission("warehouse:outbound:otherout:edit")
    //@Log(title = "修改其他出库", businessType = BusinessType.UPDATE)
    @PostMapping("/updateRest")
    public R<Void> updateRest(@RequestBody PickingRestVo pickingRestVo) throws Exception {
        return toAjax(pickingRestService.updateRest(pickingRestVo));
    }

    /**
     * 拣货提示
     */
    @GetMapping("/point/{id}")
    public R<?> point(@PathVariable("id") Long id) throws Exception {
        return R.ok(pickingRestService.point(id));
    }

    /**
     * 关结其他出库单
     */
    //@SaCheckPermission("warehouse:outbound:otherout:close")
    @Log(title = "关结其他出库单", businessType = BusinessType.UPDATE)
    @PostMapping("/closeRest")
    public R<Void> closeRest(@RequestBody PickingRestVo pickingRestVo) throws Exception {
        return toAjax(pickingRestService.closeRest(pickingRestVo));
    }

    /**
     * 删除单据
     */
    //@SaCheckPermission("warehouse:outbound:otherout:remove")
    @Log(title = "删除其他出库单据", businessType = BusinessType.DELETE)
    @DeleteMapping("/deleteRest/{ids}")
    public R<Void> deleteRest(@PathVariable("ids") String ids) throws Exception {
        return toAjax(pickingRestService.deleteRest(ids));
    }

    /**
     * 查看单据
     */
    //@SaCheckPermission("warehouse:outbound:otherout:query")
    @GetMapping("/view/{id}")
    public R<?> view(@PathVariable("id") Long id) throws Exception {

        return R.ok(pickingRestService.view(id));
    }

    /**
     * 查询其他出库列表
     */
    @GetMapping("/list")
    public TableDataInfo<PickingRestDto> getList(PickingRestVo pickingRestVo, PageQuery pageQuery) throws Exception {

        //查询其他出库列表
        return pickingRestService.getList(pickingRestVo,pageQuery);

    }

    /**
     * 导出
     */
    ////@SaCheckPermission("warehouse:outbound:otherout:export")
    // @PostMapping("/export")
    // public AjaxResult inspectionMessageExport(HttpServletResponse response, PickingRestVo pickingRestVo) throws IOException {
    //
    //
    //     List<PickingRestExport> infoExport = pickingRestService.getInfoExport(pickingRestVo);
    //     ExcelUtil<PickingRestExport> excelUtil = new ExcelUtil<PickingRestExport>(PickingRestExport.class);
    //     excelUtil.excelWriter(response, infoExport, "其他出库信息.xlsx");
    //     return AjaxResult.success();
    // }

    /**
     * 其他出库
     */
    //@SaCheckPermission("warehouse:outbound:otherout:outbound")
    @Log(title = "Pda其他出库", businessType = BusinessType.UPDATE)
    @PostMapping("/pickingRestIssue")
    public R<?> pickingRestIssue(@RequestBody PickingRestDbVo pickingRestDbVo) throws Exception {
        return R.ok(pickingRestService.pickingRestIssue(pickingRestDbVo));
    }

    /**
     * 其他出库拣货完成
     */
    @GetMapping("/pickingRestCompleted/{id}")
    @Log(title = "拣货完成", businessType = BusinessType.UPDATE)
    public R<Void> pickingRestCompleted(@PathVariable("id") Long id) throws Exception {
        return toAjax(pickingRestService.pickingRestCompleted(id));
    }

    /**
     * 其他出库拣货撤销
     */
    @GetMapping("/pickingRestRepeal/{id}")
    @Log(title = "拣货撤销", businessType = BusinessType.UPDATE)
    public R<Void> pickingRestRepeal(@PathVariable("id") Long id) throws Exception {
        return toAjax(pickingRestService.pickingRestRepeal(id));
    }

    /**
     * 其他出库交接
     */
    //@SaCheckPermission("warehouse:outbound:otherout:handover")
    @Log(title = "其他出库交接", businessType = BusinessType.UPDATE)
    @PostMapping("/pickingRestHandover")
    public R<?> pickingRestHandover(@RequestBody PickingRestDbVo pickingRestDbVo) throws Exception {
        return R.ok(pickingRestService.pickingRestHandover(pickingRestDbVo));
    }


    /**
     * 其他出库新增明细
     */
    @Log(title = "新增明细", businessType = BusinessType.UPDATE)
    @PostMapping("/addRestDetail")
    public R<Void> addRestDetail(@RequestBody PickingRestDetail pickingRestDetail) throws Exception {
        return toAjax(pickingRestService.addRestDetail(pickingRestDetail));
    }

}
